﻿<script src="~/Scripts/jquery-easyui-extensions/tree/jeasyui.extensions.tree.prev.js"></script>


<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'west',border:false,title:'这里有颗树'" style="width: 200px; border-right-width: 1px;">
        <ul id="tree"></ul>
    </div>
    <div data-options="region:'center',border:false,title:'操作面板'" style="padding:20px;">
        <div style="width:470px;height:350px;border:1px solid red;padding:10px;">
            带层级的数据源格式：
            <pre>
[
    { "id":"1","text":"A","attributes":{ "IsGay": true },
        "children":
            [
                { "id": "11", "text": "A1","attributes":{ "IsGay": true } },
                { "id": "12", "text": "A2","attributes":{ "IsGay": false } },
                { "id": "13", "text": "A3","attributes":{ "IsGay": true } }
            ] 
    },
    { "id":"2","text":"B","attributes":{ "IsGay": false } },
    { "id":"3","text":"C","attributes":{ "IsGay": false } }
]
</pre>
            <br />
            <a id="btnGet1" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 west 面板中的 tree 的“id 为 2”的节点的 prev 节点</a>
            <br />
            <br />
            <a id="btnGet2" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 west 面板中的 tree 的“id 为 11”的节点的 prev 节点</a>
            <br />
            <br />
            <a id="btnGet3" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 west 面板中的 tree 的“id 为 13”的节点的 prev 节点</a>
        </div>
    </div>
</div>

<script>
    $(function () {
        var data = [
            {
                "id": "1", "text": "A", "attributes": { "IsGay": true },
                "children":
                    [
                        { "id": "11", "text": "A1", "attributes": { "IsGay": true } },
                        { "id": "12", "text": "A2", "attributes": { "IsGay": false } },
                        { "id": "13", "text": "A3", "attributes": { "IsGay": true } }
                    ]
            },
            { "id": "2", "text": "B", "attributes": { "IsGay": false } },
            { "id": "3", "text": "C", "attributes": { "IsGay": false } }
        ];

        $("#tree").tree({
            data: data
        });


        $("#btnGet1").click(function () {
            var node = $("#tree").tree("find", 2);
            if (node) {
                var nextNode = $("#tree").tree("prev", node.target);
                if (nextNode) {
                    alert("获取到的 prev 节点是[" + nextNode.text + "]");
                } else {
                    alert("prev 节点不存在。");
                }
            }
        });

        $("#btnGet2").click(function () {
            var node = $("#tree").tree("find", 11);
            if (node) {
                var nextNode = $("#tree").tree("prev", node.target);
                if (nextNode) {
                    alert("获取到的 prev 节点是[" + nextNode.text + "]");
                } else {
                    alert("prev 节点不存在。");
                }
            }
        });

        $("#btnGet3").click(function () {
            var node = $("#tree").tree("find", 13);
            if (node) {
                var nextNode = $("#tree").tree("prev", node.target);
                if (nextNode) {
                    alert("获取到的 prev 节点是[" + nextNode.text + "]");
                } else {
                    alert("prev 节点不存在。");
                }
            }
        });
    });
</script>


